package com.zzy.action;



import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zzy.model.Product;
import com.zzy.service.ProductService;
import com.zzy.service.UserService;




@Controller

public class ProductAddAction {
	
	
	
	@Autowired
	ProductService productService;
	
	@RequestMapping("/addIndex")
	 public String login(HttpServletRequest request,Model model) {
		//前台通过${base}获取项目根路径
		String base=request.getContextPath();
		model.addAttribute("base", base);
	      return "addrenwu";
	}
	
	
	@RequestMapping("/addProduct")
	 public String addIndex(HttpServletRequest request,Model model) {
		
		 String commonName=request.getParameter("commonName");
		 String name=request.getParameter("name");
		 String vender=request.getParameter("vender");
		 String license=request.getParameter("license");
		 String function=request.getParameter("function");
		 String taboo=request.getParameter("taboo");
		 String showPrice=request.getParameter("showPrice");
		 String status=request.getParameter("status");
		 String addUserId=request.getParameter("addUserId");
		 String addUserRealname=request.getParameter("addUserRealname");
		 String addTime=request.getParameter("addTime");
		 
		 
		 
		
		 
		 Product  product=new  Product();
		 product.setAddTime(new Date());   //添加时间为当前时间
		 product.setAddUserId(addUserId);
		 product.setAddUserRealname(addUserRealname);
	     product.setCommonName(commonName);
		 product.setFunction(function);
		 product.setLicense(license);
		 product.setName(name);
		 product.setShowPrice(showPrice);
		 product.setStatus(status);
		 product.setTaboo(taboo);
		 product.setVender(vender);
		 product.setId(System.currentTimeMillis());
		 productService.add(product);
	
		  
		
		String base=request.getContextPath();
		model.addAttribute("base", base);
		return  "redirect:/listProductAction";
	     
	    
	}
}
